package com.example.yy.startproject_318yy;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.example.yy.startproject_318yy.bean.WeatherInfo;
import com.example.yy.startproject_318yy.iface.WeatherListener;
import com.example.yy.startproject_318yy.model.Weather51Model;
import com.example.yy.startproject_318yy.model.WeatherModel;

public class MainActivity extends AppCompatActivity implements WeatherListener,View.OnClickListener{

    private Button btnfind1,btnfind2;
    private EditText etcityno;
    private TextView tvcityname;
    private TextView wendu;
    private TextView fengli;
    private TextView shidu;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();

    }
    private void init(){
        etcityno=(EditText)findViewById(R.id.daima);
        btnfind1=(Button)findViewById(R.id.button1);
        btnfind2=(Button)findViewById(R.id.button2);
        tvcityname=(TextView)findViewById(R.id.textView);
        wendu=(TextView)findViewById(R.id.textView2);
        fengli=(TextView)findViewById(R.id.textView3);
        shidu=(TextView)findViewById(R.id.textView4);

        btnfind1.setOnClickListener(this);
        btnfind2.setOnClickListener(this);
    }

    @Override
    public void onResponse(WeatherInfo weatherInfo) {
        if(weatherInfo!=null){
            tvcityname.setText(weatherInfo.getCity());
            wendu.setText(weatherInfo.getTemp());
            fengli.setText(weatherInfo.getWD()+weatherInfo.getWS());
            shidu.setText(weatherInfo.getSD());

        }else{
            tvcityname.setText("未知");
            wendu.setText("none");
            fengli.setText("none");
            shidu.setText("none");
        }
    }

    @Override
    public void onFail(String msg) {
            tvcityname.setText(msg);
    }
    public void onClick(View view) {
        switch (view.getId())
        {
            case R.id.button1:   //查询1
                System.out.println("----000000");
                WeatherModel weatherModel = new WeatherModel();
                weatherModel.getWerther(etcityno.getText().toString(), this);
                break;
            case R.id.button2:  //查询2
                Weather51Model weather51Model = new Weather51Model();
                weather51Model.getWerther(etcityno.getText().toString(),this);
                break;
            default:
                break;
        }
    }


}
